package com.youlu.campus.activity.service.impl;

import com.youlu.campus.activity.repositories.ActivityTaskInfoRepository;
import com.youlu.campus.activity.service.ActivityTaskInfoService;
import com.youlu.campus.base.exception.BusinessException;
import com.youlu.campus.entity.ActivityTaskInfo;
import com.youlu.campus.entity.enums.TaskBizType;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Description: ActivityTaskInfoServiceImpl
 * @Date 2025/8/2
 * @module ActivityTaskInfoServiceImpl
 * @author: su
 */
@Slf4j
@Service
public class ActivityTaskInfoServiceImpl implements ActivityTaskInfoService {

    @Autowired
    private ActivityTaskInfoRepository repository;

    @Override
    public ActivityTaskInfo findActivityTaskInfo(String activityId, TaskBizType taskBizType) {
        log.info("findActivityTaskInfo 获取活动任务:{},{}", activityId, taskBizType);
        if (StringUtils.isBlank(activityId) || Objects.isNull(taskBizType)) {
            log.error("findActivityTaskInfo 活动ID或业务类型为空");
            throw new BusinessException("活动ID或业务类型为空");
        }
        List<ActivityTaskInfo> list = repository.findByActivityIdAndTaskBizType(activityId, taskBizType);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }

        return list.get(0);
    }
}
